package com.author.surface;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.LayoutManager;
import java.util.LinkedList;
import java.util.List;

import javax.swing.JPanel;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.border.LineBorder;

public class ToolBar extends JPanel {
	/** Width and height of the Bottom Tool Bar */
	public static int		TOOLBAR_WIDTH;
	public static int		TOOLBAR_HEIGHT;

	/** Vertical and Horizontal gap in the Bottom Tool Bar */
	public static int		HGAP			= 5;
	public static int		VGAP			= -1;

	/** Color and layout of the Bottom Tool Bar */
	private static Color	TOOLBAR_COLOR	= Color.lightGray;
	private FlowLayout		layout;

	/** List of panels inside the ToolBar */
	private List<JPanel>	panelList;

	public ToolBar(int width, int height) {
		/*
		 * The job of specifying the width and the height of the Tool Bar lies
		 * with the panel creator, which in most cases will be its parent - the
		 * ToolPanel. So the Tool Panel will specify as to how much width and
		 * height it wants the Bottom Tool Panel to have.
		 */
		ToolBar.TOOLBAR_WIDTH = width;
		ToolBar.TOOLBAR_HEIGHT = height;
		setSize(new Dimension(ToolBar.TOOLBAR_WIDTH, ToolBar.TOOLBAR_HEIGHT));
		setPreferredSize(getSize());

		// Set border of the Tool Bar
		setBorder(new EmptyBorder(2, 2, 2, 2));

		// Set the layout and the color of the Tool Bar
		layout = new FlowLayout(FlowLayout.LEADING);
		layout.setHgap(HGAP);
		layout.setVgap(VGAP);
		setLayout(layout);
		setBackground(TOOLBAR_COLOR);
		setVisible(true);
	}

	/** Add panel to the Tool Bar. Also add it to the ToolBar's list of panels */
	@Override
	public Component add(Component comp) {
		if (comp instanceof JPanel) {
			if (panelList == null) {
				panelList = new LinkedList<JPanel>();
			}
			panelList.add((JPanel) comp);
		}
		return super.add(comp);
	}

}